<template>
  <div>
    <el-form
      ref="elForm"
      :model="model"
      :rules="rules"
      size="medium"
      label-width="100px"
    >
      <el-form-item label="姓名" prop="pName">
        <el-input
          v-model="model.pName"
          placeholder="请输入姓名"
          clearable
          :style="{ width: '100%' }"
        ></el-input>
      </el-form-item>
      <el-form-item label="角色" prop="rId">
        <el-select
          v-model="model.rId"
          placeholder="请选择角色"
          clearable
          :style="{ width: '100%' }"
        >
          <el-option
            v-for="item in rIdOptions"
            :key="item.rId"
            :label="item.rName"
            :value="item.rId"
          ></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="年龄" prop="age">
        <el-input
          v-model="model.age"
          placeholder="请输入年龄"
          clearable
          :style="{ width: '100%' }"
        ></el-input>
      </el-form-item>
      <el-form-item label="学历证明" prop="trem">
        <el-input
          v-model="model.trem"
          placeholder="请输入学历证明"
          clearable
          :style="{ width: '100%' }"
        ></el-input>
      </el-form-item>
      <el-form-item label="宗教信仰" prop="cred">
        <el-input
          v-model="model.cred"
          placeholder="请输入宗教信仰"
          clearable
          :style="{ width: '100%' }"
        ></el-input>
      </el-form-item>
      <el-form-item label="手机号" prop="phone">
        <el-input
          v-model="model.phone"
          placeholder="请输入手机号"
          clearable
          :style="{ width: '100%' }"
        ></el-input>
      </el-form-item>
      <el-form-item size="large">
        <el-button type="primary" @click="submitForm">提交</el-button>
        <el-button @click="resetForm">重置</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>
<script>
import {BInd,Add} from "@/api/users";
export default {
  components: {},
  props: [],
  data() {
    return {
      model: {
        pName: undefined,
        rId: undefined,
        age: undefined,
        trem: undefined,
        cred: undefined,
        phone: undefined,
      },
      rules: {
        pName: [
          {
            required: true,
            message: "请输入姓名",
            trigger: "blur",
          },
        ],
        rId: [
          {
            required: true,
            message: "请选择角色",
            trigger: "change",
          },
        ],
        age: [
          {
            required: true,
            message: "请输入年龄",
            trigger: "blur",
          },
        ],
        trem: [
          {
            required: true,
            message: "请输入学历证明",
            trigger: "blur",
          },
        ],
        cred: [
          {
            required: true,
            message: "请输入宗教信仰",
            trigger: "blur",
          },
        ],
        phone: [
          {
            required: true,
            message: "请输入手机号",
            trigger: "blur",
          },
        ],
      },
      rIdOptions: [],
    };
  },
  computed: {},
  watch: {},
  created() {
    BInd().then((d) => {
      this.rIdOptions=d;
    })
  },
  mounted() {},
  methods: {
    submitForm() {
      this.$refs["elForm"].validate((valid) => {
        if (valid)
        {
          this.Add();
        }
        else{
          return false;
        }
      });
    },
    resetForm() {
      this.$refs["elForm"].resetFields();
    },
    Add()
    {
      Add(this.model).then((d)=>{
        if (d.data>0) {
          alert('添加成功!');
          this.$router.push('/Show');
        }
        else{
          alert('添加失败!');
        }
      })
    },
  },
};
</script>
<style>
</style>

